<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2025/3/31 16:39
 */

namespace App\Controller\User;


use App\Controller\ApiController;
use App\Request\User\UpdateUserInfoRequest;
use App\Request\User\UserCateTotalsRequest;
use App\Request\User\UserMessagesListRequest;
use App\Service\User\UserService;
use Hyperf\Di\Annotation\Inject;

class UserController extends ApiController
{


    #[Inject]
    protected UserService $userService;




    /**
     * 获取登录用户信息
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function userInfo()
    {
        return $this->responseOk($this->userService->userInfo());
    }


    public function updateUser(UpdateUserInfoRequest $request)
    {
        $data = $request->validated();

        $this->userService->userUpdate($data);

        return $this->responseOk([]);
    }


    /**
     * @param UserCateTotalsRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function userCateTotals(UserCateTotalsRequest $request)
    {
        $data = $request->validated();

        list($cateNum,$cardMemberNum) = $this->userService->userCateTotals();

        return $this->responseOk([
            'cate_num' => $cateNum,
            'card_member_num' => $cardMemberNum
        ]);
    }


    /**
     * 我的消息
     * @param UserMessagesListRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function myMessages(UserMessagesListRequest $request)
    {
        $data = $request->validated();

        $messageData = $this->userFriendsService->myApplyList($data['offset']?? 10);

        return $this->responseOk($messageData);
    }
}